package com.heima.admin.controller.v1;

import com.heima.api.wemedia.WemediaClient;
import com.heima.model.admin.dtos.AuditDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1/news")
public class AuditController {
    @Autowired
    private WemediaClient sensitiveClient;

    @PostMapping("/list_vo")
    public PageResponseResult listVo(@RequestBody AuditDto dto) {
        dto.checkParam();
        WmNewsPageReqDto wmNewsPageReqDto = new WmNewsPageReqDto();
        wmNewsPageReqDto.setStatus(dto.getStatus());
        wmNewsPageReqDto.setPage(dto.getPage());
        wmNewsPageReqDto.setSize(dto.getSize());
        wmNewsPageReqDto.setKeyword(dto.getTitle());
        wmNewsPageReqDto.setIsAdmin(WmNewsPageReqDto.ADMIN);
        return sensitiveClient.list(wmNewsPageReqDto);
    }

    @GetMapping("/one_vo/{id}")
    public ResponseResult oneVo(@PathVariable("id") Integer id) {
        if (id == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return sensitiveClient.one(id);
    }

    /**
     * 审核失败
     *
     * @param dto
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody WmNewsDto dto) {
        return sensitiveClient.authFail(dto);
    }

    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody WmNewsDto dto) {
        return sensitiveClient.authPass(dto);
    }
}
